package com.cwh.taskcenter.domain.task.model;

import com.alibaba.cola.exception.BizException;
import com.cwh.taskcenter.domain.reward.model.RewardType;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author cwh
 * 奖励规则
 */
@Data
public class BenefitRule {


    private String title;

    /**
     * 奖励类型：积分、优惠券、佣金
     */
    private String rewardType;

    /**
     * 奖励值：如果是积分、佣金那么便是实际的数值，如果是优惠券便是优惠券id
     */
    private String rewardValue;

    /**
     * 奖励有效期
     */
    private String rewardExpireTime;

    /**
     * 奖励描述
     */
    private String rewardDesc;

    public void validate() {
        if (rewardType == null || rewardType.isEmpty()) {
            throw new BizException("奖励类型不能为空");
        }
        if (StringUtils.isBlank(rewardValue)) {
            throw new BizException("奖励值不能为空");
        }
        if (Objects.equals(RewardType.COMMISSION.name(),rewardType)) {
            int commissionReward = Integer.parseInt(rewardValue);
            if (commissionReward <= 0) {
                throw new BizException("佣金奖励必须大于0");
            }
        }


        if (Objects.equals(RewardType.COUPON.name(),rewardType)) {
            // 优惠券校验逻辑

        }
    }

}
